﻿package mortal.game.view.copy.expCopy
{
    import Message.Game.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.active11.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.rebate.data.*;
    import mortal.mvc.core.*;

    public class ExpCopyRightPart extends GSprite
    {
        private var _baseItem:BaseItem;
        private var _enterBtn:GLoadingButton;
        private var _timesNumTxt:BitmapNumberText;
        private var _info:STodayExpCopyInfo;
        private var _linkTxt:GButton;

        public function ExpCopyRightPart()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._enterBtn = UIFactory.gLoadingButton(ResFileConst.ExpCopyEnterBtn, 390, 77, 114, 33, this);
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.enterCopy);
            this._linkTxt = UIFactory.gButton(Language.getString(35214), 341, 120, 130, 28, this, "GreenLinkButtonSize14");
            this._linkTxt.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._linkTxt.name = "linkTxt";
            var _loc_1:* = GlobalStyle.textFormatHuang2;
            _loc_1.size = 14;
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(35223), 58, 122, 300, 25, this, _loc_1, true));
            this._baseItem = UICompomentPool.getUICompoment(BaseItem);
            this._baseItem.setItemStyle();
            this._baseItem.itemData = new ItemData(GameConst.TConstExpCopyItemCode);
            this._baseItem.move(298, 143 - 28);
            this.addChild(this._baseItem);
            this._timesNumTxt = UIFactory.bitmapNumberText(167, 79, "ExpCopyTimesNum.png", 20, 27, 0, this, 13, BitmapNumberText.Mid);
            var _loc_2:Object = {0:0, 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, /:10};
            this._timesNumTxt.customCharIndex = _loc_2;
            this.updateItemNum();
            this.updateInfo();
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.updateItemNum);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.BackPackItemsChange, this.updateItemNum);
            this._enterBtn.dispose(param1);
            this._enterBtn = null;
            this._baseItem.dispose(param1);
            this._baseItem = null;
            this._timesNumTxt.dispose(param1);
            this._timesNumTxt = null;
            this._linkTxt.dispose(param1);
            this._linkTxt = null;
            this._info = null;
            super.disposeImpl(param1);
            return;
        }// end function

        protected function onClickHandle(event:MouseEvent) : void
        {
            var _loc_2:* = ClockManager.instance.serverOpenDateNum;
            if (Active11Util.isInActive11Card())
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.RechargeAct11DayRc200));
            }
            else if (_loc_2 <= 3)
            {
                if (RebateUtil.isActionOpen(3) && RebateUtil.isDayRechargeOpen())
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.RebateDayRechargeOpenModule));
                }
            }
            return;
        }// end function

        private function updateItemNum(param1:Object = null) : void
        {
            var _loc_2:* = Cache.instance.pack.backPackCache.getItemCountByItemCode(GameConst.TConstExpCopyItemCode, true);
            if (_loc_2 > 0)
            {
                this._baseItem.setAmountLabel(_loc_2.toString());
            }
            else
            {
                this._baseItem.setAmountLabel("<font color=\'#df2121\'>" + _loc_2 + "</font>");
            }
            return;
        }// end function

        private function enterCopy(event:MouseEvent) : void
        {
            var num:int;
            var e:* = event;
            var itemInfo:* = ItemConfig.instance.getConfig(GameConst.TConstExpCopyItemCode);
            if (this._info && this._info.enterTimes >= 1)
            {
                num = Cache.instance.pack.backPackCache.getItemCountByItemCode(GameConst.TConstExpCopyItemCode, true);
                if (num > 0)
                {
                    var closeAlert:* = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ExpCopyEnter, null));
                }
                return;
            }// end function
            ;
                    Alert.isFlowMouse = true;
                    Alert.show(Language.getStringByParam(35224, itemInfo.htmlName), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
                }
                else
                {
                    MsgManager.showRollTipsMsg(Language.getStringByParam(35225, itemInfo.htmlName), MsgRollTipsType.msgRollTips3);
                }
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ExpCopyEnter, null));
            return;
        }// end function

        private function updateInfo() : void
        {
            var _loc_1:* = ClockManager.instance.serverOpenDateNum;
            this._info = Cache.instance.copy.expCopy.getExpCopyInfoByDay(_loc_1);
            this._timesNumTxt.text = this._info ? (this._info.enterTimes.toString()) : ("0");
            this._linkTxt.visible = _loc_1 <= 3 || Active11Util.isInActive11Card();
            return;
        }// end function

    }
}
